home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-09-15 | 5.4 KB | 203 lines | [TEXT/PJMM] |
- UNIT BlastStuff;
-
- INTERFACE
-
- USES
- ROM85;
-
- PROCEDURE BlastIt;
- PROCEDURE Main; {not needed for MPW}
-
- IMPLEMENTATION
-
- PROCEDURE BlastIt;
- CONST
- buffSize = 122; { sound mode takes 2, 20 triplets = 120 bytes }
- VAR
- holeRgn, circleRgn : RgnHandle;
- theEvent : EventRecord;
- stopIt : Boolean;
- whichWindow : WindowPtr;
- thisWindow : WindowPeek;
- i, dur, cnt, minSize, pictWidth, thePart : Integer;
- blastPict : Pichandle;
- anotherRect, circleRect, tempRect : Rect;
- mouseSpot, holeSize, middlePoint : Point;
- wPort, oldPort, tempPort : GrafPtr;
- DeskPattern : ^Pattern;
- crossHairs, oldCursor : Cursor;
- TheCurs : ^Cursor;
- squareWavePtr : SWSynthPtr;
- amp : integer;
-
- BEGIN
-
- { let's set up sounds... }
- squareWavePtr := SWSynthPtr(NewPtr(buffSize));
- squareWavePtr^.mode := swMode; { squarewave mode }
- cnt := 400;
- amp := 150;
-
- { 19 triplets, with decreasing pitch and volume }
- FOR i := 0 TO 18 DO
- WITH squareWavePtr^.triplets[i] DO
- BEGIN
- count := cnt;
- amplitude := amp;
- duration := 1;
- cnt := cnt + 60;
- amp := amp - 8;
- END;
-
- WITH squareWavePtr^.triplets[19] DO
- BEGIN
- count := 0; { quit }
- amplitude := 0; { making }
- duration := 0; { sounds }
- END;
-
- { let's put up our cursor, saving the old one first...}
- { there is no 'GetCursor' call to complement 'SetCursor',}
- { so we have to dip into low memory and steal it }
- TheCurs := pointer($844);
- oldCursor := TheCurs^;
-
- { we need to put data into our cursor variable so we}
- { can do a 'SetCursor' call. stuffing the data directly}
- { into low memory doesn't work, because the cursor on the}
- { screen wouldn't change until the mouse was moved }
- StuffHex(ptr(@crossHairs), '71C7408140810000');
- StuffHex(ptr(longint(@crossHairs) + 8), '049002A041C17777');
- StuffHex(ptr(longint(@crossHairs) + 16), '41C102A004900000');
- StuffHex(ptr(longint(@crossHairs) + 24), '4081408171C70000');
- StuffHex(ptr(longint(@crossHairs) + 32), '01C0208210840808');
- StuffHex(ptr(longint(@crossHairs) + 40), '07F007F047F177F7');
- StuffHex(ptr(longint(@crossHairs) + 48), '47F107F007F00808');
- StuffHex(ptr(longint(@crossHairs) + 56), '1084208201C00000');
- StuffHex(ptr(longint(@crossHairs) + 64), '00070008');
- SetCursor(crossHairs);
-
- { make the jaggy hole }
- holeRgn := NewRgn;
- OpenRgn;
- MoveTo(250, 180);
- LineTo(260, 226);
- LineTo(230, 252);
- LineTo(260, 242);
- LineTo(232, 278);
- LineTo(270, 242);
- LineTo(286, 304); { basic hole design by Scott Boyd }
- LineTo(278, 234);
- LineTo(306, 242);
- LineTo(278, 244);
- LineTo(314, 196);
- LineTo(270, 216);
- LineTo(250, 180);
- CloseRgn(holeRgn);
-
- { "home" the region, prepare to add a circle to the middle of the hole }
- WITH holeRgn^^.rgnBBox DO
- OffsetRgn(holeRgn, -left, -top);
-
- { calculate the size of the hole and where the middle is }
- WITH holeRgn^^.rgnBBox DO
- BEGIN
- holeSize.h := right - left;
- holeSize.v := bottom - top;
- middlePoint.h := (right - left) DIV 2;
- middlePoint.v := (bottom - top) DIV 2;
- END;
-
- { figure out what size to make the circle }
- IF holeSize.h > holeSize.v THEN
- minSize := holeSize.h
- ELSE
- minSize := holeSize.v;
-
- { we'll make the circle 40% of the small dimension;}
- { minSize will be the radius of the circle }
- minSize := minSize DIV 5;
- WITH middlePoint DO
- SetRect(circleRect, h - minSize, v - minSize, h + minSize, v + minSize);
-
- { make the circle }
- circleRgn := NewRgn;
- OpenRgn;
- FrameOval(circleRect);
- CloseRgn(circleRgn);
-
- { add the circle to the hole }
- UnionRgn(holeRgn, circleRgn, holeRgn);
-
- { we don't need this any more... }
- DisposeRgn(circleRgn);
-
- { make the window manager port the current port }
- GetPort(oldPort);
- GetWMgrPort(wPort);
- SetPort(wPort);
-
- { ok, setup's all finished... here's the "main loop" }
- stopIt := FALSE;
- REPEAT
-
- { accept only mouseDown events }
- IF GetNextEvent(mDownMask, theEvent) THEN
- BEGIN
-
- { figure out where they clicked }
- thePart := FindWindow(theEvent.where, whichWindow);
-
- { respond only if they click on the content area of a window }
- IF (thePart = inContent) THEN
- BEGIN
-
- { Make some asynchrounous noise }
- StartSound(Ptr(squareWavePtr), buffSize, NIL);
-
- mouseSpot := theEvent.where;
-
- { position the hole centered over the mouse spot }
- WITH holeRgn^^.rgnBBox DO
- OffsetRgn(holeRgn, -left, -top);
- OffsetRgn(holeRgn, mouseSpot.h - holeSize.h DIV 2, mouseSpot.v - holeSize.v DIV 2);
- ThisWindow := WindowPeek(whichWindow);
- { blast a hole in the structure region }
- DiffRgn(ThisWindow^.contRgn, holeRgn, ThisWindow^.contRgn);
-
- { blast a hole in the content region }
- DiffRgn(ThisWindow^.strucRgn, holeRgn, ThisWindow^.strucRgn);
-
- { calculate and paint all new visible regions }
- CalcVisBehind(WindowPeek(whichWindow), holeRgn);
- PaintBehind(windowPeek(whichWindow), holeRgn);
-
- { and now, since 'PaintBehind' messes with the port... }
- SetPort(wPort);
- END {IF ( thePart = inContent )... }
- ELSE
- { didn't click in a window? }
- stopIt := TRUE;
- END; {IF GetNextEvent...}
- UNTIL stopIt;
-
- { clean up the hole }
- DisposeRgn(holeRgn);
-
- { fix the port }
- SetPort(oldPort);
-
- { put the old cursor back }
- SetCursor(oldCursor);
-
- { get rid of the sound buffer }
- DisposPtr(Ptr(squareWavePtr));
-
- END; {BlastIt}
-
- PROCEDURE Main; {Not needed for MPW}
- BEGIN
- BlastIt;
- END;
-
- END.